

package com.wake.widget.widget.tab;

import android.view.ViewGroup;

import com.wake.widget.widget.NMUIItemViewsAdapter;

public class NMUITabAdapter extends NMUIItemViewsAdapter<NMUITab, NMUITabView> implements NMUITabView.Callback {
    private NMUIBasicTabSegment mTabSegment;

    public NMUITabAdapter(NMUIBasicTabSegment tabSegment, ViewGroup parentView) {
        super(parentView);
        mTabSegment = tabSegment;
    }

    @Override
    protected NMUITabView createView(ViewGroup parentView) {
        return new NMUITabView(parentView.getContext());
    }

    @Override
    protected final void bind(NMUITab item, NMUITabView view, int position) {
        onBindTab(item, view, position);
        view.setCallback(this);
        // reset
        if (view.getSelectFraction() != 0f || view.isSelected()) {
            view.setSelected(false);
            view.setSelectFraction(0f);
        }
    }

    @Override
    protected void onViewRecycled(NMUITabView NMUITabView) {
        NMUITabView.setSelected(false);
        NMUITabView.setSelectFraction(0f);
        NMUITabView.setCallback(null);
    }

    protected void onBindTab(NMUITab item, NMUITabView view, int position) {
        view.bind(item);
    }

    @Override
    public void onClick(NMUITabView view) {
        int index = getViews().indexOf(view);
        mTabSegment.onClickTab(view, index);
    }

    @Override
    public void onDoubleClick(NMUITabView view) {
        int index = getViews().indexOf(view);
        mTabSegment.onDoubleClick(index);
    }

    @Override
    public void onLongClick(NMUITabView view) {
    }
}
